package com.test.controller;

import android.content.Context;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.test.R;

/**
 * 滑动进度条（电视进度条）
 */
public class SeekBarActivity extends AppCompatActivity {


    private Context context;

    private TextView seek_bar_text, seek_bar_test;

    private SeekBar seek_bar_one, seek_bar_two;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.seekbar_demo);
        //取得的是当前app所使用的application
        //返回应用的上下文，生命周期是整个应用，应用摧毁，它才摧毁。
        //context = getApplicationContext();

        //代表当前,在Activity当中就是代表当前的Activity，换句话说就是Activity.this在Activity当中可以缩写为this.
        //返回当前activity的上下文，属于activity ，activity 摧毁他就摧毁
        context = this;
        seek_bar_one = findViewById(R.id.seek_bar_one);
        seek_bar_two = findViewById(R.id.seek_bar_two);

        seek_bar_text = findViewById(R.id.seek_bar_text);
        seek_bar_test = findViewById(R.id.seek_bar_test);

        // 演示第一种滑动条（显示的提示）
        seek_bar_one.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seek_bar_text.setText("当前进度 " + i + "/100");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(context, "触碰SeekBar One", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(context, "放开SeekBar One", Toast.LENGTH_LONG).show();
            }
        });

        // 演示第二种滑动条（显示的提示）
        seek_bar_two.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seek_bar_test.setText("当前进度 " + i + "%");
                //缓冲进度条
                seek_bar_two.setSecondaryProgress(i + 20);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(context, "触碰SeekBar Two", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Toast.makeText(context, "放开SeekBar  Two", Toast.LENGTH_LONG).show();
            }

        });

        // seek_bar_two.setSecondaryProgress( 20);
    }

}
